/**
 * Copyright 2011-2011 - Members of the Chaupal Community
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package net.chaupal.Impl.v1.Message;

import java.nio.ByteBuffer;
import java.util.Map.Entry;
import net.chaupal.API.v1.Message.MessageNumber;
import net.chaupal.Impl.v1.Tools.Tools;
import net.chaupal.Impl.v1.ProtocolVersion1Impl_v1;

/**
 * API definition of the message number concept as described in the Chaupal
 * protocols.
 */
public class MessageNumberImpl_v1 extends ProtocolVersion1Impl_v1
        implements MessageNumber {

    private byte[] number = new byte[4];


    public MessageNumberImpl_v1(byte[] ba, int pos) {

        System.arraycopy(ba, pos, number, 0, 4);

    }

    @Override
    public final int compareTo(MessageNumber o) {

        if ( o == null ) return 1;
        if ( this == o ) return 0;

        return Tools.compareByteArrays(number, o.toByteArray());

    }

    /**
     * {@inheritDoc}
     *
     * This method exposes the inner byte array.
     *
     * @return the number as a byte array
     */
    @Override
    @SuppressWarnings("ReturnOfCollectionOrArrayField")
    public final byte[] toByteArray() {
        return this.number;
    }

    @Override
    public void writeIntoByteBuffer(ByteBuffer bb, int pos) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public MessageNumber readFromByteBuffer(ByteBuffer bb, int pos) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public Entry<String, String> toStringEntry() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public MessageNumber fromStringEntry(Entry<String, String> entry) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

}
